$(function () {
    init_getSetStatis();
});
/**加载数据**/
function init_getSetStatis(){
    var uuid = $("#selectUUids").val();
    $.post(ctx+"SalePhone/getSetStatis",{uuid:uuid},function (r) {
       if (r.code == 0){
           var data = r.msg;
           $.each(data,function (index,val) {
               if (val.spFenName != null){
                   var div = "<div class=\"col-md-10 form-group m-b-3\" >\n" +
                       "   <label class=\"col-md-4  control-label text-left\">"+val.spFenName+"</label>\n" +
                       "   <div class=\"col-md-7 m-t-5 input-group\">\n" +
                       "    <input type=\"text\" readonly class=\"form-control height-30\" value="+val.spTotleRecord+" />\n" +
                       "<div class=\"input-group-btn\">\n" +
                       "<button type=\"button\" class=\"btn btn-link\" onclick='disTuOther(this)' datauser='"+val.spRecer+"'>转交</button>\n" +
                       "</div>"+
                       "   </div>\n" +
                       " </div>";
                   $("#selectSetUse").append(div);
               }else{
                   $("#moveStatus").remove();
               }
               $("#title").val(val.spBatch);
           });
       }
    });
}
/**移交客户资源**/
function disTuOther(btn){
    $.post(ctx+"SalePhone/loadSaleSetUser",function (r) {
        $("#selectSetUser").empty().append(r).modal("show");
    });
    $("#selectSetUse").find("button").each(function () {
        $(this).removeAttrs("data");
    });
    $(btn).attr("data","click");
}
/**选择移交人**/
function selectSetUsers(){
    var divs = $("#user_Set_selectfor").find("div");
    if(divs.length <=0){$JuXue.n_danger("请选择转交人");return }
    var userid = divs.eq(0).attr("data-id");
    var username = divs.eq(0).text();
    $("#selectSetUse").find("button").each(function () {
        var isHave = $(this).attr("data");
        if (typeof isHave !== typeof undefined && isHave !== false) {
            $(this).find("span").each(function () {$(this).remove();});
            $(this).append("<span class='hidden' dataid='"+userid+"'>"+username+"</span>");
            $(this).parent().parent().prev().text(username);
            $("#selectSetUser").empty().modal("hide");
            return false;
        }
    });
}
/**保存信息**/
function saveSetInfo(){
    var yijiao = new Array();
    var zhjiao = new Array();
    $("#selectSetUse").find("span").each(function () {
        var zhuan = $(this).attr("dataid");
        zhjiao.push(zhuan);
        var yij = $(this).parent().attr("datauser");
        yijiao.push(yij);
    });
    var yijaodata = yijiao.join(",");
    var zhjiaodata = zhjiao.join(",");
    var uuid = $("#selectUUids").val();
    var title = $("#title").val();
    if (yijiao.length != zhjiao.length){$JuXue.n_danger("获取的数据有误");return}
    $('#diaLoadModal').empty().modal('hide');
    $.post(ctx+"SalePhone/ZhuanTaskByBatch",{"spUuid":uuid,"spRecer":yijaodata,"spFenName":zhjiaodata,"spBatch":title},function (r) {
        if (r.code == 0){$JuXue.n_success("修改成功");
        }else{$JuXue.n_danger("修改失败");}
    });
}
/**删除电话任务**/
function deleteTask(){
    var uuid = $("#selectUUids").val();
    $JuXue.confirm({
        text: "任务删除后,数据将不可恢复,是否确认删除？",
        confirmButtonText: "确定删除"
    }, function() {
        $.post(ctx+"SalePhone/deleteTaskByBatch",{uuid:uuid},function(r){
            if (r.code === 0) {
                $JuXue.n_success("删除成功");
                $('#diaLoadModal').empty().modal('hide');
                init_create_data();
            } else {
                $JuXue.n_warning("删除失败");
            }
        });
    });
}
/**移交电话完成状态**/
function moveOverStatus(){
    var uuid = $("#selectUUids").val();
    $JuXue.confirm({
        text: "把任务移动到已完成列表，将不可继续执行任务，是否确认移动？",
        confirmButtonText: "操作确认"
    }, function() {
        $.post(ctx+"SalePhone/updateTaskPhoneByUuid",{spUuid:uuid},function(r){
            if (r.code === 0) {
                $JuXue.n_success("操作成功");
                $('#diaLoadModal').empty().modal('hide');
                init_create_data();
            } else {
                $JuXue.n_warning("删除失败");
            }
        });
    });

}
